package com.geo.keyword.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.Builder;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * 关键词分析结果实体类
 * 
 * @author GEO Team
 * @version 1.0
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName("keyword_analysis_result")
public class KeywordAnalysisResult {
    
    /**
     * 分析结果ID
     */
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private String id;
    
    /**
     * 关键词ID
     */
    @TableField("keyword_id")
    private String keywordId;
    
    /**
     * 商家ID
     */
    @TableField("merchant_id")
    private String merchantId;
    
    /**
     * 分析类型
     */
    @TableField("analysis_type")
    private AnalysisType analysisType;
    
    /**
     * AI模型名称
     */
    @TableField("ai_model")
    private String aiModel;
    
    /**
     * 分析结果状态
     */
    @TableField("status")
    private AnalysisStatus status;
    
    /**
     * 竞争度分析结果 (JSON格式)
     */
    @TableField("competition_analysis")
    private String competitionAnalysis;
    
    /**
     * 搜索意图分析 (JSON格式)
     */
    @TableField("search_intent_analysis")
    private String searchIntentAnalysis;
    
    /**
     * 相关性分析 (JSON格式)
     */
    @TableField("relevance_analysis")
    private String relevanceAnalysis;
    
    /**
     * 趋势分析 (JSON格式)
     */
    @TableField("trend_analysis")
    private String trendAnalysis;
    
    /**
     * 语义分析 (JSON格式)
     */
    @TableField("semantic_analysis")
    private String semanticAnalysis;
    
    /**
     * 优化建议 (JSON格式)
     */
    @TableField("optimization_suggestions")
    private String optimizationSuggestions;
    
    /**
     * 内容策略建议 (JSON格式)
     */
    @TableField("content_strategy")
    private String contentStrategy;
    
    /**
     * 长尾关键词建议 (JSON格式)
     */
    @TableField("long_tail_suggestions")
    private String longTailSuggestions;
    
    /**
     * 竞品关键词分析 (JSON格式)
     */
    @TableField("competitor_keywords")
    private String competitorKeywords;
    
    /**
     * 机会关键词 (JSON格式)
     */
    @TableField("opportunity_keywords")
    private String opportunityKeywords;
    
    /**
     * 分析置信度 (0-100)
     */
    @TableField("confidence_score")
    private Double confidenceScore;
    
    /**
     * 分析耗时 (毫秒)
     */
    @TableField("analysis_duration")
    private Long analysisDuration;
    
    /**
     * 使用的token数量
     */
    @TableField("tokens_used")
    private Integer tokensUsed;
    
    /**
     * 分析成本
     */
    @TableField("analysis_cost")
    private Double analysisCost;
    
    /**
     * 错误信息
     */
    @TableField("error_message")
    private String errorMessage;
    
    /**
     * 原始响应 (JSON格式)
     */
    @TableField("raw_response")
    private String rawResponse;
    
    /**
     * 分析参数 (JSON格式)
     */
    @TableField("analysis_parameters")
    private String analysisParameters;
    
    /**
     * 备注
     */
    @TableField("remark")
    private String remark;
    
    /**
     * 创建时间
     */
    @TableField(value = "created_at", fill = FieldFill.INSERT)
    private LocalDateTime createdAt;
    
    /**
     * 更新时间
     */
    @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;
    
    /**
     * 创建者ID
     */
    @TableField("created_by")
    private String createdBy;
    
    /**
     * 逻辑删除标志
     */
    @TableLogic
    @TableField("deleted")
    private Integer deleted;
    
    // Getters and Setters (由@Data注解自动生成)
    
    /**
     * 分析类型枚举
     */
    public enum AnalysisType {
        BASIC("basic", "基础分析"),
        DETAILED("detailed", "详细分析"),
        COMPETITIVE("competitive", "竞争分析"),
        SEMANTIC("semantic", "语义分析"),
        TREND("trend", "趋势分析"),
        OPPORTUNITY("opportunity", "机会分析"),
        COMPREHENSIVE("comprehensive", "综合分析");
        
        private final String code;
        private final String description;
        
        AnalysisType(String code, String description) {
            this.code = code;
            this.description = description;
        }
        
        public String getCode() {
            return code;
        }
        
        public String getDescription() {
            return description;
        }
    }
    
    /**
     * 分析状态枚举
     */
    public enum AnalysisStatus {
        PENDING("pending", "待处理"),
        ANALYZING("analyzing", "分析中"),
        COMPLETED("completed", "已完成"),
        FAILED("failed", "失败"),
        CANCELLED("cancelled", "已取消");
        
        private final String code;
        private final String description;
        
        AnalysisStatus(String code, String description) {
            this.code = code;
            this.description = description;
        }
        
        public String getCode() {
            return code;
        }
        
        public String getDescription() {
            return description;
        }
    }
}